﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;

namespace testApplication
{
    class Program
    {
        static void Main(string[] args)
        {

            codeCompiler.assemblyInfo aInfo = new codeCompiler.assemblyInfo();
            aInfo.assemblyCompany = "Testfirma";
            aInfo.assemblyCopyright = "Testcopyright";
            aInfo.assemblyDescription = "Testbeschreibung";
            aInfo.assemblyProduct = "Testprodukt";
            aInfo.assemblyTitle = "Testtitel";
            aInfo.assemblyTrademark = "testtrademark";
            aInfo.Version = "1.0.0.0";

            codeCompiler.CSharpCodeCompiler csCompiler = new codeCompiler.CSharpCodeCompiler();
            csCompiler.codeFiles.Add(
                "using System;\r\n"+
                "namespace f00{\r\n"+
                "class Program {\r\n"+
                "static void Main(){\r\n"+
                "Console.WriteLine(\"Hallo Welt\");\r\n"+
                "Console.ReadKey();\r\n"+
                "}}}");

            csCompiler.codeFiles.Add(aInfo.ToString());

            csCompiler.destinationFile = @"C:\Users\Maximilian\Desktop\test.exe";
            csCompiler.Target = codeCompiler.Targets.Win32ConsoleApplication;
            csCompiler.References.Add("System.dll");
            csCompiler.generateExecutable = true;
            csCompiler.generateInMemory = true;
            csCompiler.compilerFinished += new codeCompiler.compilerFinishedEventHandler(csCompiler_compilerFinished);
            csCompiler.Compile();
            csCompiler.Dispose();
        }

        static void csCompiler_compilerFinished(object sender, codeCompiler.compilerFinishedEventArgs e)
        {
            foreach (CompilerError err in e.CompilerResults.Errors)
            {
                Console.WriteLine(err.ErrorText + "\tZeile:" + err.ErrorNumber);
            }
            Console.ReadKey();
        }
    }
}
